# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

pkgname=ruby-pycall
pkgver=1.4.2
_commit=2e48cfd1dcc0789b4453bc533930203162f84f61
pkgrel=3
pkgdesc='Calling Python functions from the Ruby language'
arch=(loong64 x86_64)
url='https://github.com/mrkn/pycall.rb'
license=(MIT)
depends=(ruby python)
makedepends=(git ruby-rake ruby-rake-compiler ruby-rspec ruby-pry ruby-pry-byebug)
checkdepends=(python-numpy)
options=(!emptydirs)
source=(git+https://github.com/mrkn/pycall.rb.git#commit=$_commit)
sha512sums=('SKIP')

prepare() {
  cd pycall.rb
  sed -r -e '/rake-compiler-dock/d' -e '/launchy/d' -i pycall.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd pycall.rb
  rake build
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    pkg/pycall-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r "tmp_install/$_gemdir/"{cache,gems/pycall-$pkgver/ext}
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd pycall.rb
  GEM_HOME="tmp_install/$_gemdir" rake spec
}

package() {
  cd pycall.rb
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
